@rem/ $Id: wg.bat 107 2009-07-15 09:11:26Z honghunter $

@echo off & color 02 & setlocal

@rem/ Init env
:Init
if "%DPS4E_HOME%"=="" call env_setting.bat

set "temp_file=tmp.file"
set "temp_dir=%CACHE_DIR%"
if not exist "%CACHE_DIR%\." set "temp_dir=c:\temp"
set "http_proxy=172.16.48.200:8366"
:::set "http_proxy="
set wget_arg=--user-agent="Mozilla/4.0 (compatible; MSIE 6.0; Windws NT 5.1)" --cookies=on
if not "%http_proxy%"=="" set http_proxy_set= -e "http_proxy=%http_proxy%"
if not "%http_proxy%"=="" set "wget_arg= %http_proxy_set% %wget_arg% "

if not exist "%temp_dir%" mkdir "%temp_dir%"

goto :main

:main
:::: * Main Process *

call :DeQuote %1
set "target_url=%return%"
if "%target_url%"=="" goto :show_error
::::  if %1=="" goto :show_error
::::  echo target_url=[%target_url%]
::::  goto :eof

if not "%2"=="" set "temp_file=%2"
wget -T 60 -t 1 %wget_arg% "%target_url%" -O%temp_dir%\%temp_file%

if not "%3"=="" copy "%temp_dir%\%temp_file%" %3 >nul
if not "%3"=="" if exist "%temp_dir%\%temp_file%" del /q/s "%temp_dir%\%temp_file%" >nul

:show_ok
echo *** *** *** *** *** ***
echo * OK
echo *** *** *** *** *** ***
::::pause
goto :eof

:show_error
echo *** *** *** *** *** ***
echo * Miss parameter
echo * Usage: %0 url [filename] [outputPath]
echo * e.g.: %0 http://nchc.dl.sourceforge.net/sourceforge/checkstyle/checkstyle-4.4.zip checkstyle-4.4.zip "c:\\"
echo *** *** *** *** *** ***
pause
goto :eof


:DeQuote
set "return=%~1"
goto:eof
